package com.hzhr.iot.collect.protocol.sender;

import com.hzhr.iot.collect.Global;
import com.hzhr.iot.collect.model.SendMessageRtnModel;
import com.hzhr.iot.huaweiiot.sdk.model.command.postCommand.PostCommandModel;
import com.hzhr.iot.huaweiiot.sdk.service.Huaweiiot_CommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class Sender1 implements Sender {
    @Autowired
    Huaweiiot_CommandService huaweiiot_commandService;
    @Autowired
    Global global;

    @Value("${version}")
    private String version;

    @Override
    public SendMessageRtnModel send(String message, String deviecId, Integer expireTime) throws Exception {
        Map<String, String> header = new HashMap<>();
        header.put("token", global.getFirstToken());
        Map<String, Object> query = new HashMap<>();
        PostCommandModel postCommandModel = new PostCommandModel();
        postCommandModel.setCommand(message);
        postCommandModel.setDeviceId(deviecId);
        postCommandModel.setExpireTime(expireTime);
        huaweiiot_commandService.postCommand(header, query, postCommandModel);

        //返回结果
        SendMessageRtnModel result = new SendMessageRtnModel();
        return result;
    }

}
